package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.OrderDetail;
import com.itheima.mapper.OrderDetailMapper;
import com.itheima.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hebing
 * @version 1.0
 */
@Service
@Transactional
public class OrderDetailServiceImpl implements OrderDetailService {
    @Autowired
    private OrderDetailMapper orderDetailMapper;

    /**
     * 保存订单详细
     *
     * @param orderDetailList
     */
    @Override
    public void save(List<OrderDetail> orderDetailList) {
        if(orderDetailList!=null&&orderDetailList.size()>0){
            for (OrderDetail orderDetail : orderDetailList) {
                //保存数据
                orderDetailMapper.insert(orderDetail);
            }
        }
    }

    /**
     * 根据订单id查询订单详情表
     *
     * @param id
     * @return
     */
    @Override
    public List<OrderDetail> seletByOrdersId(Long id) {
        //构建查询条件
        LambdaQueryWrapper<OrderDetail> lqw=new LambdaQueryWrapper<>();
        lqw.eq(id!=null,OrderDetail::getOrderId,id);
        //查询
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(lqw);
        //返回结果
        return orderDetailList;
    }
}
